<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>我的红包</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link type="text/css" rel="stylesheet" href="statics/css/style.css" />
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<script type="text/javascript"
	src="/EasyBuy/statics/js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="/EasyBuy/statics/js/menu.js"></script>
<script type="text/javascript" src="/EasyBuy/statics/js/select.js"></script>
<title>尤洪</title>
</head>

<body>
	<%@ include file="../../common/header.jsp" %>
	<%@ include file="../../common/backendHeader.jsp"%>
	
	<c:choose>
		<c:when test="${empty applicationScope.type }">
			<% 	request.getRequestDispatcher("../../UserServlet?opr=type&href=Member_Packet&href1=user").forward(request, response); %>
		</c:when>
		<c:otherwise>
			<c:if test="${applicationScope.type==1 }">
  				<%@ include file="../../common/sideMamber.jsp" %> 
			</c:if>
			<c:if test="${applicationScope.type==0 }">
				<%@ include file="../../common/sideUser.jsp" %> 
			</c:if>
		</c:otherwise>
	 </c:choose>
	
	
	<div class="m_right">
		<div class="mem_tit">我的红包</div>
		<table border="0" class="order_tab"
			style="width:930px; text-align:center; margin-bottom:30px;"
			cellspacing="0" cellpadding="0" id="tab">
			<tr>
				<td width="155">红包序号</td>
				<td width="155">红包名称</td>
				<td width="155">红包金额</td>
				<td width="155">最小订单金额</td>
				<td width="155">截止使用日期</td>
				<td width="155">红包状态</td>
			</tr>
		</table>


		<div class="mem_tit">添加红包</div>
		<form>
			<table border="0" style="width:880px;" cellspacing="0"
				cellpadding="0">
				<tr height="20">
					<td width="100" align="right">红包序列码 &nbsp; &nbsp;</td>
					<td width="300"><input id="serial" type="text" value=""
						class="add_ipt" style="width:260px;" />
					</td>
					<td><input type="button" value="生成代码" class="btn_tj" id="stb" />
					</td>
				</tr>
			</table>
		</form>
	</div>

	<%@ include file="../../common/footer.jsp"%>
	<script type="text/javascript"
		src="/EasyBuy/statics/js/jquery-1.4.2.min.js"></script>
	<script type="text/javascript">
		$(document).ready(
				function() {
					//获取当前时间
					function getNowFormatDate() {
						var date = new Date();
						var seperator1 = "-";
						var seperator2 = ":";
						var month = date.getMonth() + 1;
						var strDate = date.getDate();
						if (month >= 1 && month <= 9) {
							month = "0" + month;
						}
						if (strDate >= 0 && strDate <= 9) {
							strDate = "0" + strDate;
						}
						var currentdate = date.getFullYear() + seperator1
								+ month + seperator1 + strDate + " "
								+ date.getHours() + seperator2
								+ date.getMinutes() + seperator2
								+ date.getSeconds();

						return currentdate;
					}

					//以id查找所有的信息				
					function cha() {
						$.getJSON("red_envelopesServlet", "opr=seleall&uid=${applicationScope.id}",
								callback);
						function callback(data) {
							for ( var i = 0; i < data.length; i++) {
								var type = "";
								if (data[i].type == 1) {
									if (getNowFormatDate() < data[i].date) {
										type = "未使用";
									} else {
										type = "已过期";
									};
								} else {
									type = "已使用";
								}
								var da = data[i].date;

								$("#tab").append(
										"<tr><td>" + data[i].serial
												+ "</td><td>" + data[i].name
												+ "</td><td>" + data[i].money
												+ "</td><td>"
												+ data[i].minmoney
												+ "</td><td>" + data[i].date
												+ "</td><td>" + type
												+ "</td></tr>");
							}
						}
					}
					cha();
					$("#stb").click(
							function() {
								if ($(this).val() != "") {
									$.get("red_envelopesServlet",
											"opr=insert&serial="
													+ $("#serial").val()+"&uid=${applicationScope.id}",
											function(de) {
												alert(de);
												$("#tab tr:gt(0)").html("");
												cha();
											});
								}
							});
							$(".packet").attr("class","now");
				});
	</script>
</body>
</html>
